/*
 ============================================================================
 Name		: DownloadEngine.h
 Author	  : JohnLZeng
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CDownloadEngine declaration
 ============================================================================
 */

#ifndef DOWNLOADENGINE_H
#define DOWNLOADENGINE_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <BADESCA.H>

#include "EngineDef.h"
#include "DownloadInfoData.h"
#include "QWString.h"
#include "cx_typedef.h"
#include "cx_tinydb.h"
#include "QStoreFile.h"

// CLASS DECLARATION

/**
 *  CDownloadEngine
 * 
 */
class CDownloadEngine : public CBase
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CDownloadEngine();

	/**
	 * Two-phased constructor.
	 */
	static CDownloadEngine* NewL();

	/**
	 * Two-phased constructor.
	 */
	static CDownloadEngine* NewLC();

private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CDownloadEngine();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();

public:
	void Init();
	void Release();
	
	TInt GetAll(ArrayDownloadList& aArray);
	TInt GetRange(ArrayDownloadList& aArray,const TInt& aPos,const TInt& aLength);
	TInt Save(ArrayDownloadList& aArray);
	
//	CDownloadInfoData* AddTask(ArrayDownloadList& aArray,const TDesC& aUrl);
	TInt AddTask(ArrayDownloadList& aArray,const TInt& aPos,const TDesC& aUrl);
	void RemoveTask(ArrayDownloadList& aArray,const TInt& aPos);
	void RemoveCompeleteTask(ArrayDownloadList& aArray,const TInt& aPos);
	void RemoveTaskAndFile(ArrayDownloadList& aArray,const TInt& aPos);
	
	void StartTask(ArrayDownloadList& aArray,const TInt& aPos);
	void PauseTask(ArrayDownloadList& aArray,const TInt& aPos);
	
	void StartAll(ArrayDownloadList& aArray);
	void PauseAll(ArrayDownloadList& aArray);
	void ClearAll(ArrayDownloadList& aArray);
	
	TInt ConvertToListFormat(const ArrayDownloadList& aArray,CDesCArray* aDesC);
	TInt ConvertToListFormat(CDownloadInfoData* aItem,TDes& aFormat);

	TBool IsTaskRunningOrWaiting(ArrayDownloadList& aArray,const TInt& aPos);
private:
	TBool ExistRunningTask(ArrayDownloadList& aArray);
	
private:
	CQStoreFile iStoreFile;
	
	};

#endif // DOWNLOADENGINE_H
